home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** StandardFileIcons: A sample control panel changing behavior of StandardFile.
- **
- ** by Brian Bechtel, Apple Developer Technical Support
- **
- ** File: SFIconsInit.c
- **
- ** Copyright © 1994 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DTS Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes.
- **
- ** Change history (most recent first)
- **
- **
- ** <2> 940923 BL°B Jon Pugh noticed that I was calling DisposeHandle
- ** on a resource. This, as they say, is evil.
- ** <1> 940811 BL°B Check for System 7. Display failure icon and do
- ** nothing else if earlier than System 7. Macintosh
- ** Easy Open is the first product which actually
- ** provided the desktop icon feature; it can work all
- ** the way back to System 7, potentially.
- ** <0> 940802 BL°B First implementation
- */
-
- /*
- ** Check for the existence of our SFIcons preference file. If the file exists,
- ** then we want to use generic icons instead of the color icons Standard File Package
- ** uses. This all works only if you have System 7.5 or later (which incorporates
- ** a new Standard File Package introduced in System Update 3.0)
- **/
-
- #include <Files.h>
- #include <Folders.h>
- #include <Memory.h>
- #include <GestaltEqu.h>
- #include <ToolUtils.h>
- #include <Resources.h>
-
- #include "GestaltValue.h"
-
- enum {
- gestaltStandardFileUseGenericIcons = 3,
- kSFIconsPrefFileName = 128,
- kOurCustomIcon = 128,
- kOurGenericIcon = 129,
- kFailedIcon = 130
- };
-
-
- /* From ShowIcon7.c */
- pascal void ShowIcon7(short iconId, Boolean advance);
-
- void main(void);
- Boolean UseGenericIcons(Handle);
- void Generic(void);
- Boolean OKSystem(void);
-
- /*
- ** Get the name of our preference file from a 'STR ' resource
- ** in our control panel. Check if that preference file exists.
- ** If that preference file exists, we should set the bit in the
- ** appropriate Gestalt selector which tells the standard file
- ** package whether to use generic icons from within the PACK
- ** (faster) or grab icons from the desktop file (slower).
- **/
- void main(void)
- {
- Handle prefFileName;
-
- if (!OKSystem())
- {
- ShowIcon7(kFailedIcon, true);
- return;
- }
- prefFileName = (Handle)GetString(kSFIconsPrefFileName);
- if (prefFileName != nil)
- {
- HLock(prefFileName);
- if (UseGenericIcons(prefFileName))
- {
- Generic();
- ShowIcon7(kOurGenericIcon, true);
- }
- else
- ShowIcon7(kOurCustomIcon, true);
- HUnlock(prefFileName);
- ReleaseResource(prefFileName); // as noticed by Jon Pugh
- }
- }
-
-
-
- /*
- ** Decide to use generic icons or not. See if the preference file exists. If it
- ** exists, use generic icons.
- **/
- Boolean UseGenericIcons(Handle preferenceFileName)
- {
- OSErr err;
- FSSpec spec;
- short foundVRefNum;
- long foundDirID;
-
- err = FindFolder(kOnSystemDisk,kPreferencesFolderType,false,&foundVRefNum,&foundDirID);
- if (!err)
- err = FSMakeFSSpec(foundVRefNum,foundDirID,(StringPtr)*preferenceFileName,&spec);
- return (err == noErr);
- }
-
- /*
- ** Generic
- **
- ** Set the Gestalt bit in gestaltStandardFileAttr which says to use Generic Icons
- **/
- void Generic(void)
- {
- long gestaltValue;
- OSErr err;
-
- err = Gestalt(gestaltStandardFileAttr, &gestaltValue);
- if (!err)
- {
- gestaltValue |= (1 << gestaltStandardFileUseGenericIcons);
- ReplaceGestaltValue(gestaltStandardFileAttr, gestaltValue);
- }
- }
-
-
- /* Check System Version and return false if primary digit is < 7 (e.g. System 6)*/
- Boolean OKSystem(void)
- {
- long response;
- OSErr err;
-
- err = Gestalt(gestaltSystemVersion, &response);
-
- return ( (err == noErr) && ((response >> 8) >= 0x07) );
- }
-
-